﻿/********************************************************************************
 * Developed by Phil Tyler (http://www.laidbackcoder.co.uk)
 * 
 * Cryptosolic is Licensed under the GNU Lesser General Public License (LGPL)
 * http://cryptosolic.codeplex.com/license
 * *****************************************************************************/
using System;
using System.ComponentModel;
using Cryptosolic.Utilities;

namespace Cryptosolic.Security.Encryption.Symmetric
{
    /// <summary>
    /// Symmetric Encryption Algorithm Class
    /// </summary>
    /// <remarks>
    /// Used only to provide Base Methods to Sub Classes - DO NOT instantiate directly
    /// </remarks>
    [Browsable(false)]
	[EditorBrowsable(EditorBrowsableState.Never)]
    public abstract class SymmetricEncryptionAlgorithm : EncryptionAlgorithm, ISymmetricEncryptionAlgorithm
    {    	

        #region Crypto Methods
     
            #region Encrypt

                /// <summary>
                /// Encrypt the Human Readable Data
                /// </summary>
                /// <param name="data">Human Readable Data to be Encrypted</param>
                /// <param name="symmetricKey">Symetric Encryption/Decryption Key</param>
                /// <param name="salt">Salt</param>
                /// <param name="iV">Initialisation Vector</param>
                /// <returns>Encrypted Data</returns>
                public abstract CipherText EncryptData(byte[] data, string symmetricKey, string salt, byte[] iV);

                /// <summary>
                /// Encrypt the Human Readable Data
                /// </summary>
                /// <param name="data">Human Readable Data to be Encrypted</param>
                /// <param name="symmetricKey">Symetric Encryption/Decryption Key</param>
                /// <param name="salt">Salt</param>
                /// <param name="iV">Initialisation Vector</param>
                /// <returns>Encrypted Data</returns>
                public CipherText EncryptData(string data, string symmetricKey, string salt, byte[] iV)
                {
                    return EncryptData(DataConverter.StringToBytes(data), symmetricKey, salt, iV);
                }

                /// <summary>
                /// Encrypt the Human Readable Data
                /// </summary>
                /// <param name="data">Human Readable Data to be Encrypted</param>
                /// <param name="symmetricKey">Symetric Encryption/Decryption Key</param>
                /// <param name="iV">Initialisation Vector</param>
                /// <returns>Encrypted Data</returns>
                public CipherText EncryptData(byte[] data, string symmetricKey, byte[] iV)
                {
                    return EncryptData(data, symmetricKey, string.Empty, iV);
                }
        
                /// <summary>
                /// Encrypt the Human Readable Data
                /// </summary>
                /// <param name="data">Human Readable Data to be Encrypted</param>
                /// <param name="symmetricKey">Symetric Encryption/Decryption Key</param>
                /// <param name="iV">Initialisation Vector</param>
                /// <returns>Encrypted Data</returns>
                public CipherText EncryptData(string data, string symmetricKey, byte[] iV)
                {
                    return EncryptData(DataConverter.StringToBytes(data), symmetricKey, string.Empty, iV);
                }

            #endregion

            #region Decrypt

                /// <summary>
                /// Decrypt Encrypted Data
                /// </summary>
                /// <param name="data">Encrypted Data to be Decrypted</param>
                /// <param name="symmetricKey">Symetric Encryption/Decryption Key</param>
                /// <param name="salt">Salt</param>
                /// <param name="iV">Initialisation Vector</param>
                /// <returns>Human Readable Data</returns>
                /// <remarks>
                /// This method will throw an Exception if not Overridden!
                /// </remarks>
                public abstract PlainText DecryptData(byte[] data, string symmetricKey, string salt, byte[] iV);

                /// <summary>
                /// Decrypt Encrypted Data
                /// </summary>
                /// <param name="data">Encrypted Data to be Decrypted</param>
                /// <param name="symmetricKey">Symetric Encryption/Decryption Key</param>
                /// <param name="salt">Salt</param>
                /// <param name="iV">Initialisation Vector</param>
                /// <returns>Human Readable Data</returns>
                public PlainText DecryptData(string data, string symmetricKey, string salt, byte[] iV)
                {
                    return DecryptData(DataConverter.StringToBytes(data), symmetricKey, salt, iV);
                }

                /// <summary>
                /// Decrypt Encrypted Data
                /// </summary>
                /// <param name="data">Encrypted Data to be Decrypted</param>
                /// <param name="symmetricKey">Symetric Encryption/Decryption Key</param>
                /// <param name="iV">Initialisation Vector</param>
                /// <returns>Human Readable Data</returns>
                public PlainText DecryptData(byte[] data, string symmetricKey, byte[] iV)
                {
                    return DecryptData(data, symmetricKey, string.Empty, iV);
                }

                /// <summary>
                /// Decrypt Encrypted Data
                /// </summary>
                /// <param name="data">Encrypted Data to be Decrypted</param>
                /// <param name="symmetricKey">Symetric Encryption/Decryption Key</param>
                /// <param name="iV">Initialisation Vector</param>
                /// <returns>Human Readable Data</returns>
                public PlainText DecryptData(string data, string symmetricKey, byte[] iV)
                {
                    return DecryptData(DataConverter.StringToBytes(data), symmetricKey, string.Empty, iV);
                }

            #endregion

        #endregion
    }
}